//
// Created by fyt79 on 2019/4/21.
//

#ifndef SHORT_WAVE_RECEIVER_PSD_H
#define SHORT_WAVE_RECEIVER_PSD_H

#include <intrinsics.h>
#include <machine/machdefs.h>

#define PSD_A 0
#define PSD_B 1
#define MMIO_SB3500_BASE_ADDR 0x0fc00000
#define MMIO_SB3500A2D_A_OFF 0x0000
#define MMIO_SB3500D2A_A_OFF 0x0040
#define MMIO_SB3500PSDA_EN 0x2480
#define MMIO_SB3500PSDA_STATUS 0x2400
#define MMIO_SB3500PSDA_INT 28
#define MMIO_SB3500A2D_B_OFF 0x1000
#define MMIO_SB3500D2A_B_OFF 0x1040
#define MMIO_SB3500PSDB_EN 0x2488
#define MMIO_SB3500PSDB_STATUS 0x2408
#define MMIO_SB3500PSDB_INT 29

void psd_begin_dtoa(unsigned int psd,unsigned int buf_count, unsigned int buf_size, short* i, short* q);
void psd_stop_dtoa(unsigned int psd);
int psd_is_interrupt_dtoa(unsigned int psd);
void psd_reset_interrupt_dtoa(unsigned int psd);

void psd_begin_atod(unsigned int psd, unsigned int dec, unsigned int buf_count, unsigned int buf_size, short *i, short *q);
void psd_stop_atod(unsigned int psd);
int psdIsInterrupt_atod(unsigned int channel);
void psd_reset_interrupt_atod(unsigned int psd);

void stop_d2a(unsigned channel);

void
reset_interrupt_d2a(
  unsigned    channel    /* 0 = A, 1 = B */
);

void
start_d2a(
  unsigned    channel,    /* 0 = A, 1 = B      */
  unsigned    nbufs,      /* number of buffers */
  unsigned    nbytes,     /* bytes/per buffer  */
  unsigned short*      ibuf,       /* data              */
  unsigned short*      qbuf
);

int
is_interrupt_d2a(
  unsigned    channel
);


#endif //SHORT_WAVE_RECEIVER_PSD_H
